package fem2.observer;

import inf.text.ArrayFormat;

import java.util.ArrayList;

import fem2.Debugger;
import fem2.Node;
import fem2.Observer;

public class DisplacementObserver implements Observer {

	private ArrayList<Node> nodes;

	public DisplacementObserver(Node... n) {
		if (n != null) {
			nodes = new ArrayList<Node>();
			for (int i = 0; i < n.length; i++) {
				nodes.add(n[i]);
			}
		}
	}

	@Override
	public void fireStarted() {
	}

	@Override
	public void fireTimeStepStarted() {
	}

	@Override
	public void fireIterationStarted() {
	}

	@Override
	public void fireIterationFinished() {
		/*
		 * monitor displacement value at node
		 */
		for (int i = 0; i < nodes.size(); i++) {
			Node n = nodes.get(i);
			Debugger.watch("Displacement at node " + n.getId() + " : "
					+ ArrayFormat.format(n.getUHatLocal()));
		}
	}

	@Override
	public void fireTimeStepFinished() {
	}

	@Override
	public void fireFinished() {
	}

}
